package com.woniuxy.mesboot.controller;

import com.woniuxy.mesboot.dto.MesInspectionScheduleDTO;
import com.woniuxy.mesboot.service.MesInspectionScheduleService;
import com.woniuxy.mesboot.util.Result;
import com.woniuxy.mesboot.vo.MesInspectionScheduleVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：lisir
 * @date ：Created in 2023/5/25 15:21
 * @description：TODO
 */
@RestController
@RequestMapping("/iss")
@Slf4j
public class InspectionScheduleController {

    @Resource
    private MesInspectionScheduleService mesInspectionScheduleService;

    @PostMapping
    public Result add(@RequestBody MesInspectionScheduleDTO mesInspectionScheduleDTO) {
        int i = mesInspectionScheduleService.insertSelective(mesInspectionScheduleDTO);
        if (i > 0) {
            return Result.ok("添加成功");
        } else {
            return Result.error("添加失败");
        }
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Long id) {
        int i = mesInspectionScheduleService.deleteByPrimaryKey(id);
        if (i > 0) {
            return Result.ok("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }

    @PutMapping
    public Result update(@RequestBody MesInspectionScheduleDTO mesInspectionScheduleDTO) {
        int i = mesInspectionScheduleService.updateByPrimaryKeySelective(mesInspectionScheduleDTO);
        if (i > 0) {
            return Result.ok("更新成功");
        } else {
            return Result.error("更新失败");
        }
    }

    @GetMapping("{id}")
    public Result queryById(@PathVariable Long id) {
        MesInspectionScheduleVO mesInspectionScheduleVO = mesInspectionScheduleService.selectByPrimaryKey(id);
        if (mesInspectionScheduleVO != null) {
            return Result.ok().data("schedule",mesInspectionScheduleVO);
        } else {
            return Result.error("查询失败");
        }
    }

    @GetMapping
    public Result queryAll() {
        List<MesInspectionScheduleVO> list = mesInspectionScheduleService.selectAll();
        return Result.ok().data("list",list);
    }
}
